<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" layout:decorator="layout">
<head lang="en">
    <meta charset="UTF-8"></meta>
    <title>验证码</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div>
    <!-- 后面添加参数起到清除缓存作用 -->
    <img alt="验证码" onclick="this.src='/hu/kaptcha/render?d='+new Date()*1"  src="/hu/kaptcha/render"/>
</div>
<form id="form">
    <input type="text" name="code" />
    <input value="提交" type="button" onclick="validate()"/>
</form>
</body>
<script>
    // 匿名函数的写法
    var validate = function(){
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/hu/kaptcha/valid" ,//url
            data: $('#form').serialize(),
            success: function (result) {
                alert(result.msg);
            },
            error : function() {
                alert("异常！");
            }
        });
    }

</script>
</html>
